#ifndef JET_H
#define JET_H

#include <OgreSceneNode.h>
#include <OgreSphere.h>
#include <OgrePlane.h>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <algorithm>

#include "Track.h"
#include "TrackVector.h"
#include "Quadratic.h"

enum JetState
{
    ACCELERATING    = 0,
    BRAKING         = 1,
    TURNING         = 2,
    NONE            = 3,
    DEAD            = 4,
    FALLING         = 5
};
class Player;

const Ogre::Real JET_SIZEX = 2.0f;
const Ogre::Real JET_SIZEY = 3.5f;
const Ogre::Real JET_SIZEZ = 1.0f;

//in meter per second
const Ogre::Real JET_MAX_SPEED = 833.3333f;

//the minimum time it takes for the jet to reach its top speed
const Ogre::Real JET_MAX_ACCELERATION = 5.0f;

//the maximum HP of the jet
const Ogre::Real JET_MAX_HP = 100.0f;

//the maximum handling
const Ogre::Real JET_MAX_HANDLING = 1.0f;

//the maximum braking deacceleration
const Ogre::Real JET_MAX_BRAKING = 1.0f;

class Jet
{
    public:
        Jet(Ogre::SceneNode* root, Track* track);
        ~Jet();
        virtual void Update(float timedelta);
        virtual void Steer(float delta);
        virtual void Accelerate(float sensitivity, float timedelta);
        virtual void Brake(float sensitivity, float timedelta);
        virtual void InitNodes(unsigned int index);
        bool AdjustSkills(float acceleration, float top_speed, float handling, float shield, float braking);
        TrackVector* IsOnTrack(Track* track);

        inline void SetOwner(Player* owner)
        {
            m_owner = owner;
        }
        inline Ogre::SceneNode* GetBodyNode()
        {
            return m_bodyNode;
        }
        inline Ogre::SceneNode* GetSteeringNode()
        {
            return m_directionNode;
        }
        inline Ogre::SceneNode* GetNormalNode()
        {
            return m_normalNode;
        }
        inline void SetPosition(Ogre::Vector3 pos)
        {
            m_bodyNode->setPosition(pos);
        }
        inline unsigned int GetType()
        {
            return m_type;
        }
        inline std::string GetName()
        {
            return m_name;
        }
        inline int GetState()
        {
            return m_state;
        }
        inline Player* GetOwner()
        {
            return m_owner;
        }
        inline void SetTrack(Track* track)
        {
            m_track = track;
        }

        inline std::string GetAuthor()
        {
            return m_author;
        }
        inline void SetAuthor(std::string author)
        {
            m_author = author;
        }
        inline void SetMeshName(std::string mesh)
        {
            m_meshName = mesh;
        }
        inline std::string GetMeshName()
        {
            return m_meshName;
        }
        inline Ogre::Vector3 GetPosition()
        {
            return m_bodyNode->getPosition();
        }
        Ogre::Vector3 GetSpeed();

    protected:
        //top speed
        float               m_topSpeed;

        //max acceleration
        float               m_acceleration;

        //max braking ability
        float               m_braking;

        //the max ability to turn
        float               m_handling;

        //the max hp of the jet
        float               m_maxHP;

        //the current state of the jet
        unsigned int        m_state;

        //current speed
        float               m_currentSpeed;

        //the hp remaining
        float               m_shield;

        //the type of the jet
        unsigned int        m_type;

        //the name of the jet
        std::string         m_name;
        Player*             m_owner;
        Track*              m_track;

        std::string         m_author;
        std::string         m_meshName;

        void updateHitbox();
    private:
        Ogre::SceneNode*        m_bodyNode;
        Ogre::SceneNode*        m_normalNode;
        Ogre::SceneNode*        m_directionNode;
        Ogre::Sphere        m_hitbox;
        unsigned int        m_vectorIndex;


};

#endif // JET_H
